package com.syg.thread;

import com.syg.common.context.SygEnvConstants;
import com.syg.distributedlock.IDistributedLock;
import com.syg.logback.util.TraceUtil;
import javafx.util.Callback;

/**
 * @author oe_shenyiguang
 */
public abstract class AbstractHandler<P,T> implements IHandler<P,T>, Callback<P, T> {
    private static final String THREAD_CALL_EXCEPTION = "抽象线程处理器-线程bizId:{}-lockGoup:{}-lockKey:{}-expireTime:{}-执行发生Exception:";

    private P param;
    protected boolean handleWithLock = false;
    protected String lockGroup;
    protected String lockKey;
    protected Long expireTime;
    protected String bizId;
    String logTraceId;
    IDistributedLock lock;


    public AbstractHandler(P param) {
        this.param = param;
    }

    public AbstractHandler(P param, boolean handleWithLock, String lockKey, Long expireTime) {
        this.param = param;
        this.handleWithLock = handleWithLock;
        this.lockKey = lockKey;
        this.expireTime = expireTime;
    }

    public AbstractHandler(P param, boolean handleWithLock, String lockKey, Long expireTime, String bizId) {
        this.param = param;
        this.handleWithLock = handleWithLock;
        this.lockKey = lockKey;
        this.expireTime = expireTime;
        this.bizId = bizId;
    }

    public AbstractHandler(P param, boolean handleWithLock, String lockGroup, String lockKey, Long expireTime, String bizId) {
        this.param = param;
        this.handleWithLock = handleWithLock;
        this.lockGroup = lockGroup;
        this.lockKey = lockKey;
        this.expireTime = expireTime;
        this.bizId = bizId;
    }

    public AbstractHandler(P param, boolean handleWithLock, String lockGroup, String lockKey, Long expireTime) {
        this.param = param;
        this.handleWithLock = handleWithLock;
        this.lockGroup = lockGroup;
        this.lockKey = lockKey;
        this.expireTime = expireTime;
    }

    @Override
    public T call(P param) {
        TraceUtil.beginApplicationNameAndEnv(SygEnvConstants.get(SygEnvConstants.APPLICATION_NAME_KEY), SygEnvConstants.get(SygEnvConstants.PROFILES_ACTIVE_KEY));
        return null;
    }
}
